import React, { useState } from 'react';
import { Modal } from 'antd';
import DialogContent from './DialogContent';

/**
 * 添加设备弹框
 */
function useSelectDevice(options) {
    const { tabItems, onSelect } = options;

    const [value, setValue] = useState([]);
    const [visible, setVisible] = useState(false);

    return [
        {
            open(initialValue) {
                setValue(initialValue);
                setVisible(true);
            },
            close() {
                setVisible(false);
            },
        },
        <Modal
            destroyOnClose
            title="添加验收设备"
            width={1350}
            open={visible}
            okText="添加"
            onOk={() => {
                setVisible(false);
                onSelect(value);
            }}
            onCancel={() => {
                setVisible(false);
            }}
        >
            <DialogContent tabItems={tabItems} value={value} onChange={setValue} />
        </Modal>,
    ];
}

export default useSelectDevice;
